home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / imap / ANSI / c-client / os_t20.c < prev    next >
C/C++ Source or Header  |  1995-09-09  |  9KB  |  319 lines

  1. /*
  2.  * Program:    Operating-system dependent routines -- TOPS-20 version
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        6158 Lariat Loop NE
  6.  *        Bainbridge Island, WA  98110-2098
  7.  *        Internet: MRC@Panda.COM
  8.  *
  9.  * Date:    1 August 1988
  10.  * Last Edited:    8 September 1995
  11.  *
  12.  * Copyright 1995 by Mark Crispin
  13.  *
  14.  *  Permission to use, copy, modify, and distribute this software and its
  15.  * documentation for any purpose and without fee is hereby granted, provided
  16.  * that the above copyright notices appear in all copies and that both the
  17.  * above copyright notices and this permission notice appear in supporting
  18.  * documentation, and that the name of Mark Crispin not be used in advertising
  19.  * or publicity pertaining to distribution of the software without specific,
  20.  * written prior permission.  This software is made available "as is", and
  21.  * MARK CRISPIN DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO
  22.  * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF
  23.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL
  24.  * MARK CRISPIN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
  25.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  26.  * WHETHER IN AN ACTION OF CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT
  27.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
  28.  * THIS SOFTWARE.
  29.  *
  30.  */
  31.  
  32.  
  33. /* Dedication:
  34.  * This file is dedicated with affection to the TOPS-20 operating system, which
  35.  * set standards for user and programmer friendliness that have still not been
  36.  * equaled by more `modern' operating systems.
  37.  * Wasureru mon ka!!!!
  38.  */
  39.  
  40. /* TCP input buffer */
  41.  
  42. #define BUFLEN 8192
  43.  
  44. /* TCP I/O stream (must be before osdep.h is included) */
  45.  
  46. #define TCPSTREAM struct tcp_stream
  47. TCPSTREAM {
  48.   char *host;            /* host name */
  49.   char *localhost;        /* local host name */
  50.   int jfn;            /* jfn for connection */
  51.   char ibuf[BUFLEN];        /* input buffer */
  52. };
  53.  
  54.  
  55. #include "mail.h"
  56. #include <jsys.h>
  57. #include <time.h>
  58. #include "osdep.h"
  59. #include <sys/time.h>
  60. #include "misc.h"
  61.  
  62. #include "env_t20.c"
  63. #include "fs_t20.c"
  64. #include "ftl_t20.c"
  65. #include "nl_t20.c"
  66.  
  67. /* Server log in
  68.  * Accepts: user name string
  69.  *        password string
  70.  *        optional place to return home directory
  71.  * Returns: T if password validated, NIL otherwise
  72.  */
  73.  
  74. long server_login (char *user,char *pass,char **home,int argc,char *argv[])
  75. {
  76.   int uid;
  77.   int argblk[5];
  78.   char tmp[MAILTMPLEN];
  79.   argblk[1] = RC_EMO;        /* require exact match */
  80.   argblk[2] = (int) (user-1);    /* user name */
  81.   argblk[3] = 0;        /* no stepping */
  82.   if (!jsys (RCUSR,argblk)) return NIL;
  83.   uid = argblk[1] = argblk[3];    /* user number */
  84.   argblk[2] = (int) (pass-1);    /* password */
  85.   argblk[3] = 0;        /* no special account */
  86.   if (!jsys (LOGIN,argblk)) return NIL;
  87.   if (home) {            /* wants home directory? */
  88.     argblk[1] = 0;        /* no special flags */
  89.     argblk[2] = uid;        /* user number */
  90.     argblk[3] = 0;        /* no stepping */
  91.     jsys (RCDIR,argblk);    /* get directory number */
  92.     argblk[1] = (int) (tmp-1);    /* destination */
  93.     argblk[2] = argblk[3];    /* directory number */
  94.     jsys (DIRST,argblk);    /* get home directory string */
  95.     *home = cpystr (tmp);    /* copy home directory */
  96.   }
  97.   return T;
  98. }
  99.  
  100.  
  101. /* TCP/IP manipulate parameters
  102.  * Accepts: function code
  103.  *        function-dependent value
  104.  * Returns: function-dependent return value
  105.  */
  106.  
  107. void *tcp_parameters (long function,void *value)
  108. {
  109.   return NIL;
  110. }
  111.  
  112. /* TCP/IP open
  113.  * Accepts: host name
  114.  *        contact service name
  115.  *        contact port number
  116.  * Returns: TCP stream if success else NIL
  117.  */
  118.  
  119. TCPSTREAM *tcp_open (char *host,char *service,long port)
  120. {
  121.   char *s,tmp[MAILTMPLEN];
  122.   TCPSTREAM *stream = NIL;
  123.   int argblk[5];
  124.   int jfn;
  125.   char file[MAILTMPLEN];
  126.   if (s = strchr (host,':')) {    /* port number specified? */
  127.     *s++ = '\0';        /* yes, tie off port */
  128.     port = strtol (s,&s,10);    /* parse port */
  129.     if (s && *s) {
  130.       sprintf (tmp,"Junk after port number: %.80s",s);
  131.       mm_log (tmp,ERROR);
  132.       return NIL;
  133.     }
  134.   }
  135.   argblk[1] = monsym (".GTHPN");/* get IP address and primary name */
  136.   argblk[2] = (int) (host-1);    /* pointer to host */
  137.   argblk[4] = (int) (tmp-1);
  138.   if (!jsys (GTHST,argblk)) {    /* do it the domain way */
  139.     argblk[1] = _GTHSN;        /* failed, convert string to number */
  140.     if (!jsys (GTHST,argblk)) {    /* and do it by host table */
  141.       sprintf (tmp,"No such host as %s",host);
  142.       mm_log (tmp,ERROR);
  143.       return NIL;
  144.     }
  145.     argblk[1] = _GTHNS;        /* convert number to string */
  146.     argblk[2] = (int) (tmp-1);
  147.                 /* get the official name */
  148.     if (!jsys (GTHST,argblk)) strcpy (tmp,host);
  149.   }
  150.   sprintf (file,"TCP:.%o-%d;PERSIST:30;CONNECTION:ACTIVE",argblk[3],port);
  151.   argblk[1] = GJ_SHT;        /* short form GTJFN% */
  152.   argblk[2] = (int) (file-1);    /* pointer to file name */
  153.                 /* get JFN for TCP: file */
  154.   if (!jsys (GTJFN,argblk)) fatal ("Unable to create TCP JFN");
  155.   jfn = argblk[1];        /* note JFN for later */
  156.                 /* want 8-bit bidirectional I/O */
  157.   argblk[2] = OF_RD|OF_WR|(FLD (8,monsym("OF%BSZ")));
  158.   if (!jsys (OPENF,argblk)) {
  159.     sprintf (file,"Can't connect to %s,%d server",tmp,port);
  160.     mm_log (file,ERROR);
  161.     return NIL;
  162.   }
  163.                 /* create TCP/IP stream */
  164.   stream = (TCPSTREAM *) fs_get (sizeof (TCPSTREAM));
  165.                 /* copy official host name */
  166.   stream->host = cpystr (tmp);
  167.   argblk[1] = _GTHNS;        /* convert number to string */
  168.   argblk[2] = (int) (tmp-1);
  169.   argblk[3] = -1;        /* want local host */
  170.   if (!jsys (GTHST,argblk)) strcpy (tmp,"LOCAL");
  171.   stream->localhost = cpystr (tmp);
  172.   stream->jfn = jfn;        /* init JFN */
  173.   return stream;
  174. }
  175.  
  176. /* TCP/IP authenticated open
  177.  * Accepts: host name
  178.  *        service name
  179.  *        returned user name
  180.  * Returns: TCP/IP stream if success else NIL
  181.  */
  182.  
  183. TCPSTREAM *tcp_aopen (char *host,char *service,char *usrnam)
  184. {
  185.   return NIL;
  186. }
  187.  
  188. /* TCP/IP receive line
  189.  * Accepts: TCP/IP stream
  190.  * Returns: text line string or NIL if failure
  191.  */
  192.  
  193. char *tcp_getline (TCPSTREAM *stream)
  194. {
  195.   int argblk[5];
  196.   int n,m;
  197.   char *ret,*stp,*st;
  198.   argblk[1] = stream->jfn;    /* read from TCP */
  199.                 /* pointer to buffer */
  200.   argblk[2] = (int) (stream->ibuf-1);
  201.   argblk[3] = BUFLEN;        /* max number of bytes to read */
  202.   argblk[4] = '\012';        /* terminate on LF */
  203.   if (!jsys (SIN,argblk)) return NIL;
  204.   n = BUFLEN - argblk[3];    /* number of bytes read */
  205.                 /* got a complete line? */
  206.   if ((stream->ibuf[n - 2] == '\015') && (stream->ibuf[n - 1] == '\012')) {
  207.     memcpy ((ret = (char *) fs_get (n)),stream->ibuf,n - 2);
  208.     ret[n - 2] = '\0';    /* tie off string with null */
  209.     return ret;
  210.   }
  211.                 /* copy partial string */
  212.   memcpy ((stp = ret = (char *) fs_get (n)),stream->ibuf,n);
  213.                 /* special case of newline broken by buffer */
  214.   if ((stream->ibuf[n - 1] == '\015') && jsys (BIN,argblk) &&
  215.       (argblk[2] == '\012')) {    /* was it? */
  216.     ret[n - 1] = '\0';        /* tie off string with null */
  217.   }
  218.                 /* recurse to get remainder */
  219.   else if (jsys (BKJFN,argblk) && (st = tcp_getline (stream))) {
  220.     ret = (char *) fs_get (n + 1 + (m = strlen (st)));
  221.     memcpy (ret,stp,n);        /* copy first part */
  222.     memcpy (ret + n,st,m);    /* and second part */
  223.     fs_give ((void **) &stp);    /* flush first part */
  224.     fs_give ((void **) &st);    /* flush second part */
  225.     ret[n + m] = '\0';        /* tie off string with null */
  226.   }
  227.   return ret;
  228. }
  229.  
  230. /* TCP/IP receive buffer
  231.  * Accepts: TCP/IP stream
  232.  *        size in bytes
  233.  *        buffer to read into
  234.  * Returns: T if success, NIL otherwise
  235.  */
  236.  
  237. long tcp_getbuffer (TCPSTREAM *stream,unsigned long size,char *buffer)
  238. {
  239.   int argblk[5];
  240.   argblk[1] = stream->jfn;    /* read from TCP */
  241.   argblk[2] = (int) (buffer-1);    /* pointer to buffer */
  242.   argblk[3] = -size;        /* number of bytes to read */
  243.   if (!jsys (SIN,argblk)) return NIL;
  244.   buffer[size] = '\0';        /* tie off text */
  245.   return T;
  246. }
  247.  
  248.  
  249. /* TCP/IP send string as record
  250.  * Accepts: TCP/IP stream
  251.  *        string pointer
  252.  * Returns: T if success else NIL
  253.  */
  254.  
  255. long tcp_soutr (TCPSTREAM *stream,char *string)
  256. {
  257.   int argblk[5];
  258.   argblk[1] = stream->jfn;    /* write to TCP */
  259.   argblk[2] = (int) (string-1);    /* pointer to buffer */
  260.   argblk[3] = 0;        /* write until NUL */
  261.   if (!jsys (SOUTR,argblk)) return NIL;
  262.   return T;
  263. }
  264.  
  265.  
  266. /* TCP/IP send string
  267.  * Accepts: TCP/IP stream
  268.  *        string pointer
  269.  *        byte count
  270.  * Returns: T if success else NIL
  271.  */
  272.  
  273. long tcp_sout (TCPSTREAM *stream,char *string,unsigned long size)
  274. {
  275.   int argblk[5];
  276.   argblk[1] = stream->jfn;    /* write to TCP */
  277.   argblk[2] = (int) (string-1);    /* pointer to buffer */
  278.   argblk[3] = -size;        /* write this many bytes */
  279.   if (!jsys (SOUTR,argblk)) return NIL;
  280.   return T;
  281. }
  282.  
  283. /* TCP/IP close
  284.  * Accepts: TCP/IP stream
  285.  */
  286.  
  287. void tcp_close (TCPSTREAM *stream)
  288. {
  289.   int argblk[5];
  290.   argblk[1] = stream->jfn;    /* close TCP */
  291.   jsys (CLOSF,argblk);
  292.                 /* flush host names */
  293.   fs_give ((void **) &stream->host);
  294.   fs_give ((void **) &stream->localhost);
  295.   fs_give ((void **) &stream);    /* flush the stream */
  296. }
  297.  
  298.  
  299. /* TCP/IP return host for this stream
  300.  * Accepts: TCP/IP stream
  301.  * Returns: host name for this stream
  302.  */
  303.  
  304. char *tcp_host (TCPSTREAM *stream)
  305. {
  306.   return stream->host;        /* return host name */
  307. }
  308.  
  309.  
  310. /* TCP/IP return local host for this stream
  311.  * Accepts: TCP/IP stream
  312.  * Returns: local host name for this stream
  313.  */
  314.  
  315. char *tcp_localhost (TCPSTREAM *stream)
  316. {
  317.   return stream->localhost;    /* return local host name */
  318. }
  319.